package com.steven.logserver.mq;

import com.steven.logserver.config.RabbitMqConfig;
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 * 通过SimpleMessageListenerContainer 来消费
 *
 * @author qinxiaohu
 *
 */
@Component
public class MsgReceiverContainer {

    @Autowired
    private RabbitMqConfig rabbitMqConfig;
    @Autowired
    private DirectExchangeCollocation collocation;
    @Autowired
    private MqCommons mqCommons;
    @Autowired
    private MsgListener msgListener;

    /**
     * 消费者3配置
     *
     * @return SimpleMessageListenerContainer
     */
    @Bean
    public SimpleMessageListenerContainer messageContainer() {

        SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(rabbitMqConfig.connectionFactory());
        mqCommons.getContainer(container, msgListener, collocation.queue());

        return container;
    }
}
